﻿<!DOCTYPE html>
<!--部门编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <script src="../static/js/Resource/RisksManagement.js"></script>
    <script src="../static/js/Mock/RisksManagement.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .el-input__suffix {
            /* z-index: 9; */
        }
    </style>
    <style>
        .el-input-number__increase {
            right: -4px;
        }

        .el-input-number.is-controls-right .el-input-number__decrease {
            right: -4px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini"
                 label-position="right">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{SysDepartment.ParentId+mark.m}}
                                </template>
                                <treeselect v-model="Form.parentId" :options="DepartmentList" :flat="true" slot="suffix"
                                            style="line-height: 28px;width:70%;float: right;" placeholder="请选择" />
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.name" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SysDepartment.Name+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <input-factorys-all :span="11" :offset="2" v-model="Form.CreateFactory" :disabled="true"></input-factorys-all>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.code" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SysDepartment.Code+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <div class="el-input el-input--mini el-input-group el-input-group--prepend">
                            <div class="el-input-group__prepend">
                                {{SysDepartment.Sort+mark.m}}
                            </div>
                            <div>
                                <el-input-number class="el-input__inner" v-model="Form.sort" :min="1" label="描述文字"
                                                 size="mini">
                                </el-input-number>
                            </div>

                        </div>
                    </div>
                </el-col>

            </el-row>



            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{SysDepartment.Remark+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.remark"
                                          autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>

                </el-col>
            </el-row>


            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                    <!-- <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button> -->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                //业务表单内容
                Form: {
                    CreateFactory:null,
                },
                DepartmentList: [],//下拉树
                //表单验证
                rules: {

                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            console.log('mythis.Form', mythis.Form)
                            onSubmitForm(this, '/api/SysDepartment/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });

                },
                getData: function () {
                    getData(this, '/api/SysDepartment/get?id=' + this.id);
                },
                GetPageData: function (currentIndex) {
                    var dataSource = parent.ListItem.dataSource
                    var data = MenuHelper(dataSource, null);
                    this.DepartmentList = data;
                    this.DepartmentList.unshift({ id: null, label: '无父级', Id: guidEmpty })//初始化无父级的选项
                },
            },
            mounted: function () {
                var app = this;
                this.id = getUrlParam("id");
                this.GetPageData(1);//绑定下拉树
                this.getData();
                this.$nextTick(function () {
                    app.Form.CreateFactory = parent.app.formInline.model.createFactory;
                });
            }
        });

        //数据序列化（下拉树）
        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (v.parentId == pid) {
                    var obj = v;
                    obj.id = obj.id + '';
                    obj.label = obj.name + '';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>